/**
 * Project: complex.java
 * 
 * File Created at 2011-3-23
 * $Id: CglibTest.java 137 2011-03-23 06:18:04Z ymkyve501@163.com $
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package complex.java.compiler;
import java.lang.reflect.Method;  
import net.sf.cglib.proxy.Enhancer;  
import net.sf.cglib.proxy.MethodInterceptor;  
import net.sf.cglib.proxy.MethodProxy;
/**
 * TODO Comment of CglibTest
 * @author gaoliang
 *
 * @date 2011-3-23
 */
public class CglibTest {
    public static void main(String[] args) {  
        
        Enhancer enhancer = new Enhancer();  
        enhancer.setSuperclass(MyClass.class);  
        enhancer.setCallback(new MethodInterceptorImpl());  
        MyClass my = (MyClass) enhancer.create();  
        my.print();  
      }  
      
      private static class MethodInterceptorImpl implements MethodInterceptor {  
        public Object intercept(Object obj, Method method, Object[] args,  
            MethodProxy proxy) throws Throwable {  
          // log something  
          System.out.println(method + " intercepted!");  
      
          proxy.invokeSuper(obj, args);  
          return null;  
        }  
      } 
}
